﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 车牌识别系统1
{
    public partial class Form4 : Form
    {
        public static string a;
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sex = "";
            string str = "";
            string jgk = "";
            string shk = "";
            shk = textBox4.Text;
            sex = textBox1.Text;
            str = textBox2.Text;
            jgk = textBox3.Text;
             string sqlStr = "server=.;database=cpsm;integrated security=SSPI";
            SqlConnection conn = new SqlConnection(sqlStr);
            conn.Open();
            string selectsql = string.Format("Select * from table_5 ", conn);
            SqlCommand com = new SqlCommand(selectsql, conn);
            com.CommandType = CommandType.Text;
            SqlDataReader sdr;
            sdr = com.ExecuteReader();
            while (sdr.Read())
            {
                if (textBox2.Text.Trim() == sdr["renyuanming"].ToString().Trim())
                {
                   a = "公司人员";
                }
                else 
                   a = "普通用户";
            }
            sdr.Close();
            conn.Close();


            if (textBox3.Text == textBox4.Text)
            {
                string SqlStr = "server=.;database=cpsm;integrated security=SSPI";
                SqlConnection con = new SqlConnection(SqlStr);
                con.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = con;
                comm.CommandText = "insert into table_2(numb,leibie) values( '" + textBox1.Text + "','"+a+"');insert into table_1(userid,psw) values('" + textBox2.Text + "','" + textBox3.Text + "')";
                if (comm.ExecuteNonQuery() > 0)
                    MessageBox.Show("注册成功", "正确", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Form3 f3 = new Form3();
                f3.Show();
                this.Hide();
            }
            else

                MessageBox.Show("两次密码输入不一致，请重新输入！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            textBox1.Focus();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.Show();
            this.Hide();
        }
    }
}
